package logic

import (
	"context"
	"product/model/mysql"

	"product/productrpc/internal/svc"
	"product/productrpc/productrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type RatesAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewRatesAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RatesAddLogic {
	return &RatesAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 评论添加
func (l *RatesAddLogic) RatesAdd(in *productrpc.RatesAddRequest) (*productrpc.RatesAddResponse, error) {
	// todo: add your logic here and delete this line
	rates := mysql.Rates{
		UserId:    in.UserId,
		ProductId: in.ProductId,
		Content:   in.Content,
	}
	mysql.DB.Debug().Create(&rates)

	return &productrpc.RatesAddResponse{
		Id: int64(rates.ID),
	}, nil
}
